<?php

/**
* LogoutTest.php
*
* Guid add test
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once '../framework/config.php';

require_once 'simpletest/autorun.php';
require_once 'simpletest/web_tester.php';

require_once '../framework/AuthSingleton.php';


class  LogoutTest extends WebTestCase
{

    private $dbh = '';
    private $username = '';
    private $password = '';


    public function setUp() 
    {
        $this->username = md5( uniqid( rand(), true ) )."@pl.pl";
        $this->password = "zuza";
        $this->msg = md5( uniqid( rand(), true ) );

        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $this->url = $global['service_url'];

        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');  
        $this->dbh = new PDO($options['dsn_string']); 
        $this->dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

        $this->addHeader("User-Agent: Mozilla/5.0(SymbianOS/9.2; U; Series60/3.1 NokiaE51/1.00.000; Profile/MIDP-2.0 Configuration/CLDC-1.1;)AppleWebKit/413(KHTML,like Gecko)Safari/413");

        $this->get($this->url.'?');
        AuthSingleton::instance('AUTH_USER')->addUser($this->username,$this->password);
        $this->setFieldByName('username', $this->username);
        $this->setFieldByName('password', $this->password);
        $this->click("Login");
        $this->assertTitle('Polowanie na kody');
        $this->assertText('Mapa poglądowa oraz lista trofeów');
        AuthSingleton::instance()->addUser($this->username,$this->password);


    }

    public function testLogoutLinkExists()
    {
        $this->assertLink('Logout',$this->url.'?logout=1');
    }

    public function testLogout()
    {
        $this->assertLink('Logout',$this->url.'?logout=1');
        $this->click('Logout');
        $this->assertText('Podaj login i hasło!');
    }

    public function testLogoutLoginUser()
    {
        $this->assertLink('Logout',$this->url.'?logout=1');
        $this->click('Logout');
        $this->assertText('Podaj login i hasło!');
        $this->setFieldByName('username', $this->username);
        $this->setFieldByName('password', $this->password);
        $this->click("Login");
        $this->assertTitle('Polowanie na kody');
        $this->assertText('Mapa poglądowa oraz lista trofeów');
    } 

    public function testLogoutUserLoginAdmin()
    {
        $this->assertLink('Logout',$this->url.'?logout=1');
        $this->click('Logout');
        $this->assertText('Podaj login i hasło!');
        $this->get($this->url.'/adm');
        $this->assertText('>Login');
        $this->setFieldByName('username', $this->username);
        $this->setFieldByName('password', $this->password);
        $this->click("Login");
        $this->assertText('Wybierz kod do edycji');
    } 


    public function tearDown() 
    {
      
        AuthSingleton::instance('AUTH_USER')->removeUser($this->username);
        AuthSingleton::instance()->removeUser($this->username);
        $this->get($this->url.'?cmd=AdminAddCode&logout=1');
        $this->get($this->url.'?cmd=CodeList&logout=1');
    }
 

}
?>
